package com.sskj.run.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;
import com.sskj.run.bean.CoinTypeBean;
import com.sskj.run.bean.RankBean;
import com.sskj.run.http.HttpConfig;
import com.sskj.run.ui.fragment.RankFragment;

import java.util.List;

import io.reactivex.Flowable;


public class RankFragmentPresenter extends BasePresenter<RankFragment> {

    /**
     * 排行榜列表
     */
    public Flowable<List<RankBean>> getRankList(String money_type, String type, int page, int size) {
        return httpService.rankList(money_type, type, page, size)
                .converter(new JsonConverter<HttpData<PageBean<RankBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(listHttpData -> listHttpData.getData().getList());
    }

    public void getCoinType() {
        httpService.getCoinType()
                .execute(new JsonCallBack<HttpData<List<CoinTypeBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<CoinTypeBean>>> response) {
                        HttpData<List<CoinTypeBean>> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.initSpinner(httpData.getData());
                        }
                    }
                });
    }
}
